
var url = "https://dav.jianguoyun.com/dav/";
var name = "";//账号
var pass = "";//密钥
var code = base64(name + ":" + pass);

// 上传下载,上传的文件是下载的专用的......

//这个是上传
let str1 = shell("cat /sdcard/1/ceshi.zip | base64").result
上传("我的坚果云/",str1)
function 上传(path, str) {

    var res = http.request(url + path, {
        method: "PUT",
        headers: {
            "Authorization": "Basic " + code,
            "Content-Type": "text/plain;charset=UTF-8",
            "Connection": "Keep-Alive",
            "Accept-Encoding": "gzip",
            "User-Agent": "okhttp/3.12.1"
        },
        body: str
    });
     log(res.body.string());
};

//下载,只能用上传的文件
获取("我的坚果云/ceshi.zip")


function 获取(path) {
    //获取一个资源文件
    //ar url = "Put/Writer.txt";
    var res = http.get(url + path, {
        headers: {
            "Authorization": "Basic " + code,
            "Content-Type": "text/plain;charset=UTF-8",
            "Connection": "Keep-Alive",
            "Accept-Encoding": "gzip",
            "User-Agent": "okhttp/3.12.1"
        }
    });

    var zipFile=res.body.bytes()
    var zippath="/sdcard/ck.zip"
    files.writeBytes(zippath,zipFile)
    sleep(1000)
    //ck1.zip是下载的文件,如果存在,删除已下载文件
    shell("rm -f /sdcard/ck2.zip ")
    sleep(1000)
    shell("cat /sdcard/ck.zip | base64 -d >> /sdcard/ck2.zip")
    sleep(1000)
    shell("rm -f /sdcard/ck.zip")
    log("下载完成");
};




function base64(str) {
    return java.lang.String(android.util.Base64.encode(java.lang.String(str).getBytes(), 2));
};
